package com.hdaccp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @RequestMapping(value = {"/hello","hello1","hello2"},method = {RequestMethod.POST,RequestMethod.GET},params = {"age"})
    public String hello(){
        System.out.println("hello sprinmvc!");
        return "index" ;
    }
    @RequestMapping("/save")
    public String save(@RequestParam(value = "name",required = false,defaultValue = "小明") String username){
        System.out.println("username = " + username);
        return "success" ;
    }
    @RequestMapping("/query")
    public ModelAndView query(){
        ModelAndView modelAndView = new ModelAndView("success") ;
        modelAndView.addObject("address","河北邯郸") ;
        return modelAndView ;
    }
    @RequestMapping("/get")
    public String  get(Model model){
        model.addAttribute("phone","1388888888") ;
        return "success" ;
    }

    @RequestMapping("/get1")
    public String  get1(Map<String,Object> map){
        map.put("email","qq@qq.com") ;
        return "success" ;
    }
    @RequestMapping("/doGet")
    public String doGet(HttpServletRequest request){
        request.setAttribute("gender","男");
        return "success" ;
    }

}
